package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "菜品相关接口")
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Resource
    private DishService dishService;


    /**
     * @description: 新增菜品
     * @author: tanbobin
     * @date: 2024/5/30 16:37
     * @param:
     * @param dishDTO
     * @return:
     * @return com.sky.result.Result
     **/
    @ApiOperation("新增菜品")
    @PostMapping
    public Result save(@RequestBody DishDTO dishDTO){
        log.info("新增菜品数据, {}", dishDTO);
        dishService.save(dishDTO);
        return Result.success();
    }

    /**
     * @description: 分页条件查询
     * @author: tanbobin
     * @date: 2024/5/31 9:45
     * @param:
     * @return:
     * @return com.sky.result.Result<com.sky.result.PageResult>
     **/
    @ApiOperation("分页条件查询")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO pageQueryDTO){
        log.info("分页条件查询,{}", pageQueryDTO);
        PageResult pageResult = dishService.page(pageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * @description: 删除菜品
     * @author: tanbobin
     * @date: 2024/5/31 16:26
     * @param:
     * @param ids
     * @return:
     * @return com.sky.result.Result
     **/
    @ApiOperation("删除菜品")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("批量删除菜品, {}", ids);
        dishService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * @description: 根据id查询用于页面回显
     * @author: tanbobin
     * @date: 2024/5/31 16:27
     * @param:
     * @param id
     * @return:
     * @return com.sky.result.Result<com.sky.vo.DishVO>
     **/
    @ApiOperation("根据id查询用于页面回显")
    @GetMapping("/{id}")
    public Result<DishVO> getInfo(@PathVariable Long id){
        log.info("根据id查询用于页面回显, {}", id);
        DishVO dishVO = dishService.getInfo(id);
        return Result.success(dishVO);
    }

    /**
     * @description: 修改菜品信息
     * @author: tanbobin
     * @date: 2024/5/31 16:29
     * @param:
     * @param dishDTO
     * @return:
     * @return com.sky.result.Result
     **/
    @ApiOperation("修改菜品信息")
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("修改菜品信息, {}", dishDTO);
        dishService.update(dishDTO);
        return Result.success();
    }

    /**
     * @description: 菜品起售、停售
     * @author: tanbobin
     * @date: 2024/6/5 15:49
     * @param:
     * @param status
     * @param id
     * @return:
     * @return com.sky.result.Result
     **/
    @ApiOperation("菜品起售、停售")
    @PutMapping("/status/{status}/{id}")
    public Result updateStatus(@PathVariable Integer status, @PathVariable Long id){
        log.info("菜品起售、停售,{} ,{}",status, id);
        dishService.updateStatus(status, id);
        return Result.success();
    }
}
